package com.cwh.taskcenter.web.system.sms;

import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.SingleResponse;
import com.cwh.taskcenter.system.sms.SmsTemplateAddCmd;
import com.cwh.taskcenter.system.sms.api.SmsTemplateService;
import com.cwh.taskcenter.system.sms.dto.data.SmsTemplateVO;
import com.cwh.taskcenter.system.sms.dto.query.SmsTemplatePageQry;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


/**
 * @author cwh
 */
@Tag(name = "管理后台 - 短信模板")
@RestController
@RequestMapping("/api/system/sms-template")
public class SmsTemplateController {


    @Autowired
    private SmsTemplateService smsTemplateService;


    @PostMapping("/create")
    @Operation(summary = "创建短信模板")
    public SingleResponse<Long> createSmsTemplate(@Valid @RequestBody SmsTemplateAddCmd req) {
        return SingleResponse.of(smsTemplateService.createSmsTemplate(req));
    }

    @PutMapping("/update")
    @Operation(summary = "更新短信模板")
    public SingleResponse<Boolean> updateSmsTemplate(@Valid @RequestBody SmsTemplateAddCmd updateReqVO) {
        smsTemplateService.updateSmsTemplate(updateReqVO);
        return SingleResponse.of(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除短信模板")
    @Parameter(name = "id", description = "编号", required = true)
    public SingleResponse<Boolean> deleteSmsTemplate(@RequestParam("id") Long id) {
        smsTemplateService.deleteSmsTemplate(id);
        return SingleResponse.of( true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得短信模板")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public SingleResponse<SmsTemplateVO> getSmsTemplate(@RequestParam("id") Long id) {
        SmsTemplateVO template = smsTemplateService.getSmsTemplate(id);
        return SingleResponse.of(template);
    }

    @GetMapping("/page")
    @Operation(summary = "获得短信模板分页")
    public PageResponse<SmsTemplateVO> getSmsTemplatePage(@Valid SmsTemplatePageQry pageVO) {
        return  smsTemplateService.getSmsTemplatePage(pageVO);
    }


}
